/**
 * Created by tms on 17/11/7.
 * 时间动画引擎，
 */
function TimerAnimate() {

    var self = this;


    //动画队列
    self.runQueue = new Array();


    self.Counter = 0;

    var start = null;
    var lastTimestamp = null;


    self.AddQueue=function (obj) {
        self.runQueue.push(obj);

    }



    self.Run = function (timestamp) {


        var delta = 0;

        if (start == null) {
            start = timestamp;
            lastTimestamp = timestamp;
        }
        self.Counter++;

        delta = timestamp - lastTimestamp;
        //console.log(delta + 'ms');
        lastTimestamp = timestamp;


        //处理队列

        var myLen=self.runQueue.length-1;
        for(var i=myLen;i>=0;i--){

            var handler=self.runQueue[i];


            //队列中已经不存在了
            if(typeof(handler)=='undefined'){
                //需要remove
                self.runQueue.splice(i,1);

            }else{
                handler.Animate(self.Counter);
            }



        }//end for



        if(self.Counter>9999){
            self.Counter=0;//防止出界
        }



        requestAnimationFrame(self.Run);
    }


    //根据分组key,删除一组对象

    self.removeQueueByGroupKey=function (GroupKey) {

        var len=self.runQueue.length;
        for(var i=len-1;i>=0;i--){
            var item=self.runQueue[i];
            if(item.GroupKey==GroupKey){
                //need remove this item
                tmsMap.animateLayer.remove(item.oldObject);
                self.runQueue.splice(i,1);

            }

        }

    }

}

var timerAnimate=new TimerAnimate();
timerAnimate.Run();